package com.galaxy.payment.controller;

import com.galaxy.common.core.domain.R;
import com.galaxy.common.mybatis.core.page.PageQuery;
import com.galaxy.common.mybatis.core.page.TableDataInfo;
import com.galaxy.payment.domain.bo.AccountFlowBo;
import com.galaxy.payment.domain.vo.AccountFlowVo;
import com.galaxy.payment.service.IAccountFlowService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;

/**
 * 资金流水记录接口
 */
@RestController
@RequestMapping("/payment/accountFlow")
@RequiredArgsConstructor
public class AccountFlowController {

    private final IAccountFlowService accountFlowService;

    /**
     * 取消充值
     */
    @PostMapping("/cancelRecharge/{rechargeNo}")
    public R<Boolean> cancelRecharge(@PathVariable String rechargeNo) {
        return R.ok(accountFlowService.cancelRecharge(rechargeNo));
    }

    /**
     * 根据主键查询流水
     */
    @GetMapping("/{id}")
    public R<AccountFlowVo> queryById(@PathVariable Long id) {
        return R.ok(accountFlowService.queryById(id));
    }

    /**
     * 分页查询流水列表
     */
    @GetMapping("/page")
    public TableDataInfo<AccountFlowVo> queryPageList(AccountFlowBo bo, PageQuery pageQuery) {
        return accountFlowService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询流水列表
     */
    @GetMapping("/list")
    public R<List<AccountFlowVo>> queryList(AccountFlowBo bo) {
        return R.ok(accountFlowService.queryList(bo));
    }

    /**
     * 新增流水
     */
    @PostMapping
    public R<Boolean> insertByBo(@RequestBody @Valid AccountFlowBo bo) {
        return R.ok(accountFlowService.insertByBo(bo));
    }

    /**
     * 修改流水
     */
    @PutMapping
    public R<Boolean> updateByBo(@RequestBody @Valid AccountFlowBo bo) {
        return R.ok(accountFlowService.updateByBo(bo));
    }

    /**
     * 批量删除流水
     */
    @DeleteMapping("/batch")
    public R<Boolean> deleteWithValidByIds(@RequestBody Collection<Long> ids, @RequestParam(defaultValue = "false") Boolean isValid) {
        return R.ok(accountFlowService.deleteWithValidByIds(ids, isValid));
    }

    /**
     * 根据用户ID查询流水
     */
    @GetMapping("/user/{userId}")
    public R<List<AccountFlowVo>> queryByUserId(@PathVariable Long userId) {
        return R.ok(accountFlowService.queryByUserId(userId));
    }

    /**
     * 根据订单号查询流水
     */
    @GetMapping("/order/{orderNo}")
    public R<AccountFlowVo> queryByOrderNo(@PathVariable String orderNo) {
        return R.ok(accountFlowService.queryByOrderNo(orderNo));
    }
}
